<?php
class PostsController extends AppController {
	var $name = 'Posts';
	
	function index(){
		$this->set('posts', $this->Post->find('all'));
	}
	
	function view($id = null){
		$this->Post->id = $id;
		$this->set('post',$this->Post->read());
	}
	
	function add(){
		if (!empty($this->data)) {
			if ($this->Post->save($this->data)) {
				$this->Session->setFlash('Data yang dikirim dari form berhasil disimpan!');
				$this->redirect(array('action' => 'index'));
			}
		}
	}
	
	function delete($id){
		$this->Post->del($id);
		$this->Session->setFlash('Data dengan ID: '.$id.' sudah dihapus!');
		$this->redirect(array('action' => 'index'));
	}
	
	function edit($id = null){
		$this->Post->id = $id;
		if(empty($this->data)){
			$this->data = $this->Post->read();
		} else {
			if ($this->Post->save($this->data)) {
				$this->Session->setFlash('Data sudah terupdate');
				$this->redirect(array('action' => 'index'));
			} 
		}
	}
}
?>